Completed
Push — master ( 9da91a...c60c2b )
by Maxence
02:22
created

nav.displayNonMemberInteraction   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 19
rs 9.4285
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: nav */
31
/** global: elements */
32
/** global: curr */
33
/** global: api */
34
35
36
var nav = {
37
38
39
	initNavigation: function () {
40
		this.initElementsMemberNavigation();
41
		this.initElementsCircleNavigation();
42
43
		this.displayCirclesList('all');
44
	},
45
46
47
	initElementsMemberNavigation: function () {
48
49
		elements.addMember.on('input propertychange paste focus', function () {
50
			var search = $(this).val().trim();
51
			if (search === '') {
52
				elements.membersSearchResult.fadeOut(400);
53
				return;
54
			}
55
56
			actions.searchMembersRequest(search);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
57
			if (elements.membersSearchResult.children().length === 0) {
58
				elements.membersSearchResult.fadeOut(400);
59
			} else {
60
				elements.membersSearchResult.fadeIn(400);
61
			}
62
		}).blur(function () {
63
			elements.membersSearchResult.fadeOut(400);
64
		});
65
	},
66
67
	initElementsCircleNavigation: function () {
68
69
		elements.joinCircle.on('click', function () {
70
			api.joinCircle(curr.circle, actions.joinCircleResult);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
71
		});
72
73
		elements.leaveCircle.on('click', function () {
74
			api.leaveCircle(curr.circle, actions.leaveCircleResult);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
75
		});
76
77
		elements.destroyCircle.on('click', function () {
78
			OC.dialogs.confirm(
79
				t('circles', 'Are you sure you want to destroy this circle ?'),
80
				t('circles', 'Please confirm'),
81
				function (e) {
82
					if (e === true) {
83
						api.destroyCircle(curr.circle, actions.destroyCircleResult);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
84
					}
85
				});
86
		});
87
88
		elements.joinCircleAccept.on('click', function () {
89
			api.joinCircle(curr.circle, actions.joinCircleResult);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
90
		});
91
92
		elements.joinCircleReject.on('click', function () {
93
			api.leaveCircle(curr.circle, actions.leaveCircleResult);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
94
		});
95
	},
96
97
98
	displayCirclesList: function (type) {
99
100
		curr.circlesType = type;
101
		curr.searchCircle = '';
102
		curr.searchUser = '';
103
104
		curr.circle = 0;
105
		curr.circleLevel = 0;
106
107
		elements.navigation.show('slide', 800);
108
		elements.emptyContent.show(800);
109
		elements.mainUI.fadeOut(800);
110
111
		elements.circlesSearch.val('');
112
		elements.addMember.val('');
113
114
		this.resetCirclesTypeSelection(type);
115
		elements.resetCirclesList();
116
		api.searchCircles(type, '', 0, actions.listCirclesResult);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
117
	},
118
119
120
	resetCirclesTypeSelection: function (type) {
121
		elements.circlesList.children('div').removeClass('selected');
122
		elements.circlesList.children().each(function () {
123
			if ($(this).attr('circle-type') === type.toLowerCase()) {
124
				$(this).addClass('selected');
125
			}
126
		});
127
	},
128
129
	/**
130
	 *
131
	 * @param display
132
	 */
133
	displayOptionsNewCircle: function (display) {
134
		if (display) {
135
			elements.newType.fadeIn(300);
136
			elements.newSubmit.fadeIn(500);
137
			elements.newTypeDefinition.fadeIn(700);
138
		}
139
		else {
140
			elements.newType.fadeOut(700);
141
			elements.newSubmit.fadeOut(500);
142
			elements.newTypeDefinition.fadeOut(300);
143
		}
144
	},
145
146
147
	displayMembers: function (members) {
148
149
		elements.remMember.fadeOut(300);
150
		elements.rightPanel.fadeOut(300);
151
152
		elements.mainUIMembers.emptyTable();
153
		if (members === null) {
154
			elements.mainUIMembers.hide(200);
155
			return;
156
		}
157
158
		elements.mainUIMembers.show(200);
159
		for (var i = 0; i < members.length; i++) {
160
			var tmpl = elements.generateTmplMember(members[i]);
161
			elements.mainUIMembers.append(tmpl);
162
		}
163
164
		$('tr.entry').on('click', function () {
165
			nav.displayMemberDetails($(this).attr('member-id'), $(this).attr('member-level'),
166
				$(this).attr('member-levelstring'), $(this).attr('member-status'));
167
		});
168
	},
169
170
171
	displayMemberDetails: function (id, level, levelstring, status) {
172
173
		level = parseInt(level);
174
		curr.member = id;
175
		curr.memberLevel = level;
176
		curr.memberStatus = status;
177
178
		elements.rightPanel.fadeIn(300);
179
		elements.memberDetails.children('#member_name').text(id);
180
		if (level === 0) {
181
			levelstring += ' / ' + status;
182
		}
183
		elements.memberDetails.children('#member_levelstatus').text(levelstring);
184
185
		this.displayMemberDetailsAsModerator();
186
	},
187
188
189
	displayMemberDetailsAsModerator: function () {
190
		if (curr.circleLevel >= 6 && curr.memberLevel < curr.circleLevel) {
191
			if (curr.memberStatus === 'Requesting') {
192
				elements.memberRequest.fadeIn(300);
193
				elements.remMember.fadeOut(300);
194
			}
195
			else {
196
				elements.memberRequest.fadeOut(300);
197
				elements.remMember.fadeIn(300);
198
			}
199
		} else {
200
			elements.remMember.fadeOut(300);
201
			elements.memberRequest.fadeOut(300);
202
		}
203
	},
204
205
206
	displayCircleDetails: function (details) {
207
		elements.circlesDetails.children('#name').text(details.name);
208
		elements.circlesDetails.children('#type').text(t('circles', details.typeLongString));
209
	},
210
211
212
	displayMembersInteraction: function (details) {
213
		if (details.user.level < 6) {
214
			elements.addMember.hide();
215
		} else {
216
			elements.addMember.show();
217
		}
218
219
		elements.joinCircleInteraction.hide();
220
		this.displayNonMemberInteraction(details);
221
222
		if (details.user.level === 9) {
223
			elements.joinCircle.hide();
224
			elements.leaveCircle.hide();
225
			return;
226
		}
227
228
		if (details.user.level >= 1) {
229
			elements.joinCircle.hide();
230
			elements.leaveCircle.show();
231
		}
232
	},
233
234
235
	displayNonMemberInteraction: function (details) {
236
		elements.joinCircleAccept.hide();
237
		elements.joinCircleReject.hide();
238
		elements.joinCircleRequest.hide();
239
		elements.joinCircleInvite.hide();
240
241
		if (details.user.status === 'Invited') {
242
			this.displayInvitedMemberInteraction();
243
			return;
244
		}
245
246
		if (details.user.status === 'Requesting') {
247
			this.displayRequestingMemberInteraction();
248
			return;
249
		}
250
251
		elements.joinCircle.show();
252
		elements.leaveCircle.hide();
253
	},
254
255
256
	displayInvitedMemberInteraction: function () {
257
		elements.joinCircleInteraction.show();
258
		elements.joinCircleInvite.show();
259
		elements.joinCircleAccept.show();
260
		elements.joinCircleReject.show();
261
		elements.joinCircle.hide();
262
		elements.leaveCircle.hide();
263
	},
264
265
	displayRequestingMemberInteraction: function () {
266
		elements.joinCircleInteraction.show();
267
		elements.joinCircleRequest.show();
268
		elements.joinCircle.hide();
269
		elements.leaveCircle.show();
270
	}
271
272
};
273
274